package collection

import "soluty.cc/go/godash/types"

func Find(array []T, predicate types.Predicate, fromIndex ...int) (ret T) {
	startIndex := 0
	if len(fromIndex) > 0 {
		startIndex = fromIndex[0]
	}
	if startIndex < 0 {
		startIndex = 0
	}
	if startIndex > len(array)-1 {
		return
	}
	for i := startIndex; i < len(array); i++ {
		if predicate(array[i], i, array) {
			ret = array[i]
			break
		}
	}
	return
}
